package br.com.beyondclick.view;

import javax.ejb.EJB;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.log4j.Logger;

import br.com.beyondclick.model.repository.MaterialRepository;
/**
 * @jsp.tag name="listarMaterial" body-content="empty"
 */
public class ListaMaterialTag extends TagSupport{
	private static final long serialVersionUID = 1L;
	private final static Logger logger = Logger.getLogger(ListaMaterialTag.class);

	@EJB(beanName="MaterialRepositoryBeanRemote")
	private MaterialRepository materialRepository;

	@Override
	public int doStartTag() throws JspException {
		try{
			HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();

			request.setAttribute("materiais", materialRepository.find());

		}catch(Exception e){
			logger.warn("Erro ao recuperar a lista de materiais.", e);
		}
		
		return SKIP_BODY;
	}
}
